package org.common.utils.exceltosql;
import org.common.utils.tool.EnvTool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * @author zhouzhibing
 * @date 2025/4/11
 */
public class ExcelToMysql {

    private static final Logger log = LoggerFactory.getLogger(ExcelToSqlFile.class);

    /**
     * -D"generator.xlsx.dir"="D:\Excel" -D"generator.sql.dir"="D:\Excel\sql\" -D"mysql.host"="10.30.126.161:3306/test" -D"mysql.username"=root -D"mysql.password"=root
     * @param args 程序参数
     */
    public static void main(String[] args) {
        Map<String, String> allEnv = EnvTool.getAllEnv();
        String generatorXlsxDir = allEnv.get("generator.xlsx.dir");
        String generatorSqlDir = allEnv.get("generator.sql.dir");
        String mysqlHost = allEnv.get("mysql.host");
        String mysqlUsername = allEnv.get("mysql.username");
        String mysqlPassword = allEnv.get("mysql.password");

        if(generatorXlsxDir == null || generatorSqlDir == null || mysqlHost == null || mysqlUsername == null || mysqlPassword == null) {
            String message = """
                    
                    Please check the parameters, as shown in the following example: 
                    -Dgenerator.xlsx.dir=D:\\Excel
                    -Dgenerator.sql.dir=D:\\Excel\\sql\\
                    -Dmysql.host=10.30.126.161:3306/test
                    -Dmysql.username=root
                    -Dmysql.password=root""";
            log.info(message);
            return;
        }

//        ExcelToSqlFile.generateSql("D:\\Excel" , "D:\\Excel\\sql\\");
//        SqlFileToMysql.executeToMysql("10.30.126.161:3306/test" , "root" , "root" , "d:\\Excel\\sql\\");

        ExcelToSqlFile.generateSql(generatorXlsxDir , generatorSqlDir);
        SqlFileToMysql.executeToMysql(mysqlHost , mysqlUsername , mysqlPassword , generatorSqlDir);

        log.info("ExcelToMysql success!");
    }
}
